package homework;

public class EmailValidator {
    public static boolean isValidEmail(String email) {
        if (email == null || email.isEmpty())
            return false;

        int atIndex = email.indexOf('@');
        int dotIndex = email.lastIndexOf('.');

        // 基本验证
        if (atIndex <= 0 || dotIndex <= atIndex ||
                dotIndex == email.length() - 1) {
            return false;
        }

        // 不能有连续的点或@
        if (email.contains("..") || email.contains("@.") ||
                email.contains(".@")) {
            return false;
        }

        return true;
    }

    public static void main(String[] args) {
        String[] emails = {"test@example.com", "invalid@", "no.at.sign"};
        for (String email : emails) {
            System.out.println(email + ": " + isValidEmail(email));
        }
    }
}
